/*
 * Command.h
 *
 *  Created on: 2012-12-27
 *      Author: yangentao@gmail.com
 */

#pragma once;
#include "../yet/net/BaseSocket.h"
#include "Packet.h"
#include "FtpContext.h"
#include "ITask.h"

namespace ftp {
using namespace yet;

class Task: public ITask {
	typedef ITask Super;
public:
	Task();
	Task(FtpContext* context);
	virtual ~Task();
public:
	Task& connect(string host, u_short port);
	Task& login(string username, string password, string account = "");
	Task& quit();
	Task& noop();
	Task& pwd();
	Task& cwd(string pathname);
	Task& syst(); //215 UNIX Type: L8
	Task& rename(string from, string to);
	Task& cdup();
	Task& type(string type); //A|E|I|L[N|T|C]   //TODO type AN;  type L8
	Task& abor();
	Task& dele(string pathname);
	Task& rmd(string pathname);
	Task& mkd(string pathname);

	//ABOR ACCT ALLO APPE CDUP CWD  DELE EPRT EPSV FEAT HELP LIST MDTM MKD
	//MODE NLST NOOP OPTS PASS PASV PORT PWD  QUIT REIN REST RETR RMD  RNFR
	//RNTO SITE SIZE SMNT STAT STOR STOU STRU SYST TYPE USER XCUP XCWD XMKD
	//XPWD XRMD
	Task& help(string s = "");
	Task& pasv();
	Task& list(string pathname = "");
	Task& nlst(string pathname = "");
	Task& retr(string remotefile, string localPath);
	Task& stor(string localfile, string remotefile);
	Task& stou(string localfile);	//not support by filezilla
	Task& appe(string localfile, string remotefile);
	Task& rest(int offset);
	Task& rein();	//not support by filezilla
	Task& site(string s);

	//FEAT
	//211-Features:
	// MDTM
	// REST STREAM
	// SIZE
	// MLST type*;size*;modify*;
	// MLSD
	// UTF8
	// CLNT
	// MFMT
	//211 End
	Task& feat();
	Task& opts(string cmd, string options="");
public:
	//not tested
	Task& acct(string account);
	Task& smnt(string pathname);
	Task& port(string host, short port);
	Task& stru(string stru);
	Task& mode(string mode);
	Task& allo(string n, string n2 = "");
	Task& stat(string pathname = "");
public:
	bool execute();
private:
	//APPE, LIST, NLST, REIN, RETR, STOR, and STOU
	void onWait(Packet* p);
	bool onDataTransfer(void* p);
	bool download(Packet* p);
	bool upload(Packet* p);
	bool list(Packet* p);
	bool nlst(Packet* p);
private:
	bool processCommand(Packet* p);
public:
	boost::shared_ptr<Packet> packet;
	string localPath;
};

} /* namespace yet */
